package com.xigege.netty.inboundHandlerAndOutboundHandler.server;

import com.xigege.netty.inboundHandlerAndOutboundHandler.coder.MyByteToLongDecoder;
import com.xigege.netty.inboundHandlerAndOutboundHandler.coder.MyLongToByteEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

public class MyServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        //入站，从pipeline头开始走，
        // 会先调用MyByteToLongDecoder，再调用MyServerHandler

        //入站的handler进行解码 MyByteToLongDecoder
        //inboundHandler和outboundHandler各走各的不冲突
        pipeline.addLast(new MyByteToLongDecoder());
        pipeline.addLast(new MyLongToByteEncoder());
        //入站
        pipeline.addLast(new MyServerHandler());
    }
}
